package com.yanqu.road.server.cmd.activity.tongbing;

import com.yanqu.road.entity.activity.tongbing.config.TongBingConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.TongBingProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.tongbing.TongBingModule;
import com.yanqu.road.server.gameplayer.module.patrons.PatronsModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.tongbing.TongBingMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.List;

@Cmd(code = GameProtocol.S_TONG_BING_UPDATE_PATRONS_ABILITY, desc = "")
public class TongBingUpdatePatronsAbilityCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        TongBingConfig config = TongBingMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        if (!config.inEnterActivityTime()) {
            ret = GameErrorCode.E_TONG_BING_NO_OPERATE_TIME;
            return;
        }
        TongBingMgr.syncTongBingPatronsAbility(player, false);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret == 0) {
            return;
        }

        TongBingProto.TongBingUpdatePatronsAbilityRespMsg.Builder respMsg = TongBingProto.TongBingUpdatePatronsAbilityRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(ClientProtocol.U_TONG_BING_UPDATE_PATRONS_ABILITY, respMsg);
    }
}
